/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package visualization;

import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.DrawContext;
import gov.nasa.worldwind.render.Polyline;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lukas
 */
public class PolyLineLayer extends RenderableLayer
{
    private GroundData gData;

    public PolyLineLayer(GroundData gData)
    {
        this.gData = gData;
    }

    public void render(DrawContext dc)
    {

        for (int i = 0; i < gData.pingsNumber; i++)
        {
            for (int j = 0; j < gData.beamsNumber - 1; j++)
            {
                List<Position> positions = new ArrayList<Position>();
                Position pos = gData.positions[i][j];

                int k = j + 1;
                Position pos2 = gData.positions[i][k];

                float greenComponent;
                try
                {
                    greenComponent = (float) (Math.abs(pos.elevation - gData.minElevation) / gData.difference);
                }
                catch (Exception e)
                {
                    return;
                }
                
                if (greenComponent < 0.0f)
                {
                    greenComponent = 0.0f;
                }
                else if (greenComponent > 1.0f)
                {
                    greenComponent = 1.0f;
                }

                Color cl = new Color(1.0f, greenComponent, 0.0f);
                positions.add(pos);
                positions.add(pos2);

                Polyline poly = new Polyline(positions);
                poly.setColor(cl);
                poly.setLineWidth(3);
                try
                {
                    poly.render(dc);
                }
                catch (Exception e)
                {
                }
            }
        }
    }
}
